﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master" Inherits="System.Web.Mvc.ViewPage<Ditto.Models.Transaction>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Edit</h2>

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>

<% using (Html.BeginForm()) { %>
    <% Html.EnableClientValidation(); %>
    <%: Html.ValidationSummary("Please correct the errors and try again.") %>

    <fieldset style="border-style:none">
    <div id="itemDiv" class="vevent">
        <div class="widget">

            <h2>Transaction</h2>

            <p>
                <%: Html.DisplayFor(model => model.Item.Title) %>
            </p>

            <h3>Pickup Details</h3>

            <p>
                <%: Html.LabelFor(model => model.PickupAddress) %>
                <%: Html.EditorFor(model => model.PickupAddress) %>
            </p>

            <p>
                <%: Html.LabelFor(model => model.PickupTime) %>
                <%: Html.EditorFor(model => model.PickupTime) %>
            </p>

            <p>
                <%: Html.LabelFor(model => model.IsPickedup) %>
                <%: Html.EditorFor(model => model.IsPickedup) %>
            </p>


            <% if (Model.ReturnTime.HasValue)
               { %>
            <h3>Return Details</h3>

            <p>
                <%: Html.LabelFor(model => model.ReturnAddress)%>
                <%: Html.EditorFor(model => model.ReturnAddress)%>
            </p>

            <p>
                <%: Html.LabelFor(model => model.ReturnTime)%>
                <%: Html.EditorFor(model => model.ReturnTime)%>
            </p>

            <p>
                <%: Html.LabelFor(model => model.IsReturned)%>
                <%: Html.EditorFor(model => model.IsReturned)%>
            </p>

            <%} %>

             <p>
                <input type="submit" value="Save" class="button"/>
            </p>
        </div>
    </div>


    <div id="mapDiv">

        <div class="widget">
                    <p>
                <strong>Pickup at:</strong>
                <span class="location adr">
                    <span class="extended-address"><%: Model.PickupAddress %></span>
<%--                    <span class="country-name"><%: Model.Country %></span>--%>
                    <abbr class="geo" title="<%: Model.PickupLatitude %>;<%: Model.PickupLongitude %>" style="display: none;">Geolocation for hCalendar</abbr>
                </span>
            </p>
            <%: Html.EditorFor(m => m.PickupLocation) %>
        </div>
        
        <div class="widget">
                    <p>
                <strong>Return at:</strong>
                <span class="location adr">
                    <span class="extended-address"><%: Model.ReturnAddress %></span>
<%--                    <span class="country-name"><%: Model.Country %></span>--%>
                    <abbr class="geo" title="<%: Model.ReturnLatitude %>;<%: Model.ReturnLongitude %>" style="display: none;">Geolocation for hCalendar</abbr>
                </span>
            </p>
            <%: Html.EditorFor(m => m.ReturnLocation) %>
        </div>

    </div>
    </fieldset>
<% } %>

    <script type="text/javascript">
//<![CDATA[
        $(document).ready(function () {
            Ditto.EnableMapMouseClickCallback();

            $("#PickupAddress").blur(function (evt) {
                //If it's time to look for an address, 
                // clear out the Lat and Lon
                $("#PickupLatitude").val("0");
                $("#PickupLongitude").val("0");
                var address = jQuery.trim($("#PickupAddress").val());
                if (address.length < 1)
                    return;
                Ditto.FindAddressOnMap(address);
            });
            Ditto.FindAddressOnMap("<%: Model.PickupLocation.Address %>");

            $("#ReturnAddress").blur(function (evt) {
                //If it's time to look for an address, 
                // clear out the Lat and Lon
                $("#ReturnLatitude").val("0");
                $("#ReturnLongitude").val("0");
                var address = jQuery.trim($("#ReturnAddress").val());
                if (address.length < 1)
                    return;
                Ditto.FindAddressOnMap(address);
            });
            Ditto.FindAddressOnMap("<%: Model.ReturnLocation.Address %>");
        });
//]]>
    </script>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadArea" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="MastheadContent" runat="server">
</asp:Content>
